package com.team7.home.controller;


import com.team7.common.utils.OSSUtil;
import com.team7.common.vo.BannerVo;
import com.team7.common.vo.CommonResult;
import com.team7.home.service.impl.BannerServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author 张煜杰
 * @since 2021-10-19
 */

@RestController
@RequestMapping("/home/banner")
public class BannerController {
    @Autowired
    private BannerServiceImpl bannerService;

    @PostMapping("getAllBanner/{page}/{limit}")
    public CommonResult getAllHeadNav(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit, @RequestBody BannerVo bannerVo){
        return bannerService.getAllHeadNar(page,limit,bannerVo);
    }

    @PostMapping("changeStatus/{id}/{isDisable}")
    public CommonResult changeStatus(@PathVariable("id") String id,@PathVariable("isDisable") Integer isDisable){
        return bannerService.changeStatus(id,isDisable);
    }
    /**
     * 后台中的图片上传
     * @param file
     * @return
     */
    @PostMapping("uploadMsg")
    public String uploadMsg(MultipartFile file){
        return OSSUtil.getOssUrl(file);
    }

    /**
     * 前台的图片上传
     * @param picFile
     * @return
     */
    @PostMapping("upload")
    public String upload(@RequestParam("picFile") MultipartFile picFile){
        String ossUrl = OSSUtil.getOssUrl(picFile);
        return ossUrl;
    }

    @PostMapping("addBanner")
    public CommonResult addBanner(@RequestBody BannerVo bannerVo){
        return bannerService.addHeadNav(bannerVo);
    }

    @PostMapping("deleteBanner")
    public CommonResult deleteHeadNav(@RequestBody BannerVo bannerVo){
        return bannerService.deleteHeadNav(bannerVo.getId());
    }

}

